<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :pager-count="pagerCount"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    >
    </el-pagination>
    <div class="cuasrsa" @click="handleCurrentChange">GO</div>
  </div>
</template>

<script>
import { scrollTo } from '@/utils/scroll-to'

export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    // 移动端页码按钮的数量端默认值5
    pagerCount: {
      type: Number,
      default: document.body.clientWidth < 992 ? 5 : 7
    },
    layout: {
      type: String,
      default: 'sizes, prev, pager, next, jumper'
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
    };
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    },
  },
  mounted () {
   document.getElementsByClassName('el-pagination__jump')[0].childNodes[0].nodeValue = '跳转至'
   document.getElementsByClassName('el-pagination__jump')[0].childNodes[2].nodeValue = ''
   console.log(document.getElementsByClassName('el-pagination__jump')[0].childNodes[2].nodeValue)
  },
  methods: {
    handleSizeChange(val) {
      console.log('2')
      if (this.currentPage * val > this.total) {
        this.currentPage = 1
      }
      this.$emit('pagination', { page: this.currentPage, limit: val })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      console.log('1')
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.pagination-container {
  background: #fff;
  padding: 32px 16px;
}
.pagination-container.hidden {
  display: none;
}

</style>
<style lang="scss">
.pagination-container .el-pagination .el-pager li.number.active {
  color: #1890ff;
  cursor: default;
  border-color: #1890ff !important;
  border-width: 1px !important;
  border-style: solid !important;
  border-radius: 5px;
}
.el-pager li {
  padding: 0px 4px;
  background: #FFFFFF;
  vertical-align: top;
  display: inline-block;
  font-size: 13px;
  min-width: 30.5px;
  height: 27px;
  line-height: 25px;
  cursor: pointer;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-align: center;
  margin-top: 1px;
}
.cuasrsa {
  right: 9px;
  position: absolute;
  width: 25px;
  height: 28px;
  /* background-color: bisque; */
  align-items: center;
  justify-content: center;
  display: flex;
  border-color: #c9c9c9 !important;
  border-width: 1px !important;
  border-style: solid !important;
  border-radius: 0px 5px 5px 0px;
  margin-top: 2px;
  font-weight: 500;
  cursor: pointer;
}
.el-pagination__editor.el-input .el-input__inner {
  height: 28px;
  width: 37px;
  border-radius: 5px 0px 0px 5px;
}
.pagination-container .el-pagination {
  right: 20px;
  position: absolute;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  text-align: center;
  margin: 0;
}
.el-pagination__jump {
  margin-left: 0px;
  font-weight: normal;
  color: #606266;
}
</style>
